package charset;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.SplittableRandom;

public class Test1 {
    public static void main(String[] args) throws Exception {
        // 编码
        String data = "a我b";
        byte[] bytes = data.getBytes(StandardCharsets.UTF_8);
        System.out.println(Arrays.toString(bytes));

        // 自定义字符集编码
        byte[] bytes1 = data.getBytes("GBK");
        System.out.println(Arrays.toString(bytes1));




        // 解码
        String s1 = new String(bytes);
        System.out.println(s1);

        String s2 = new String(bytes1);
        System.out.println(s2);
    }
}
